package com.wangmengtao.upms.controller;

import com.wangmengtao.upms.dto.EasyuiTree;
import com.wangmengtao.upms.model.UpmsPermission;
import com.wangmengtao.upms.service.UpmsPermissionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: UpmsPermissionController
 * @Description: TODO
 * @Author: WangMengtao
 * @Data: 2019/6/5 17:15
 * @Version: 1.0.0
 */
@RestController
public class UpmsPermissionController {

    protected Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    UpmsPermissionService upmsPermissionService;

    @PostMapping(value = "/permissions")
    public Object create(@RequestBody UpmsPermission upmsPermission) {
        logger.info("id :" + upmsPermission.getName());
        return upmsPermissionService.insert(upmsPermission);
    }

    @DeleteMapping(value = "/permissions/{id}")
    public Object deleteById(@PathVariable("id") Long id) {
        return upmsPermissionService.deleteById(id);
    }

    @PutMapping(value = "/permissions/update")
    public Object update(UpmsPermission upmsPermission) {
        return upmsPermissionService.update(upmsPermission);
    }

    @GetMapping(value = "/permissions/{id}")
    public Object getByid(@PathVariable("id") Long id) {
        return upmsPermissionService.getById(id);
    }

    @GetMapping(value = "/permissions")
    public Object list() {
        return upmsPermissionService.list();
    }

    @GetMapping(value = "/permissions/tree")
    private List<EasyuiTree> tree() {
        return upmsPermissionService.tree();
    }

}
